﻿<%@ Page Title="" Language="C#" MasterPageFile="~/EventsParent.Master" AutoEventWireup="true" CodeBehind="Users.aspx.cs" Inherits="WebFrontEnd.Users" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link href="css/jtable-themes/lightcolor/gray/jtable.min.css" rel="stylesheet" />
    <script type="text/javascript" src="js/jquery.jtable.min.js"></script>
    <script type="text/javascript" src="js/jquery.jtable.aspnetpagemethods.min.js"></script>
    <script type="text/ecmascript">
        $(function () {
            $("#UsersTable").jtable({
                title: 'User\'s Table',
                paging: true,
                pageSize: 10,
                sorting: true,
                defaultSorting: 'Name ASC',
                actions: {
                    listAction: 'Services/GuestsService.asmx/ListUsers',
                    deleteAction: 'Services/GuestsService.asmx/DeleteUser'
                },
                fields: {
                    ID: {
                        key: true,
                        list: false
                    },
                    FirstName: {
                        width: '16%',
                        title: 'First Name'
                    },
                    LastName: {
                        width: '16%',
                        title: 'Last Name'
                    },
                    Email: {
                        width: '16%',
                        title: 'Email'
                    },
                    Role: {
                        width: '16%',
                        title: 'Role',
                        options: { '0': 'Admin', '1': 'User' }
                    },
                    LoginAs: {
                        width: '8%',
                        title: '',
                        display: function (data) {
                            return '<a href="LoginAs.aspx?id=' + data.record.ID + '">Login as ' + data.record.FirstName + '</a>';
                        }
                    },
                    ChangeRole: {
                        title: '',
                        width: '8%',
                        display: function (data) {
                            var innerText = "";
                            if (data.record.Role == 0) {
                                innerText = 'Strip of admin priviledges';
                            } else {
                                innerText = 'Raise to admin';
                            }
                            var $a = $('<a href="#">' + innerText + '</a>');
                            $a.click(function () {
                                $.ajax({
                                    type: "POST",
                                    url: "Services/GuestsService.asmx/ChangePrivilege",
                                    data: JSON.stringify({ 'id': data.record.ID }),
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    success: function (response) {
                                        response = response.d;
                                        $("#UsersTable").jtable('load');
                                    }
                                });
                                return false;
                            });
                            return $a;
                        }
                    }

                }
            });
            $("#UsersTable").jtable('load');
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="NavBar" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row-fluid">
        <div id="UsersTable"></div>
    </div>
</asp:Content>
